/***************************************************
> Copyright (C) 2024 ==KINGYI== All rights reserved.
> File Name: employee_menu.c
> Author:MOKI
> Mail:1913964829@qq.com 
> Created Time: 2024年09月13日 星期五 18时25分44秒
***************************************************/
#include "global.h"
void employeeManage()
{
    int choice = -1, quit_flag = 0;
    while (1)
    {
        printf("***************************************\n");
        printf("员工菜单：\n");
        printf("1.完善个人信息\n");
        printf("2.管理植物信息\n");
        printf("3.管理游客信息\n");
        printf("4.管理监控信息\n");
        printf("5.管理环境信息\n");
        printf("0.返回上一级\n");
        printf("输入选择：");
        setbuf(stdin, NULL);
        scanf("%d", &choice);
        switch (choice)
        {
        case 1:
            updataEmployee();
            break;
        case 2:
            managePlants();
            break;
        case 3:
            manageVisitor();
            break;
        case 4:
            manageSurveillanceData();
            break;
        case 5:
            manageEnvironmentData();
            break;
        case 0:
            quit_flag = 1;
            break;
        default:
            printf("输入错误重新输入\n");
            break;
        }
        if (quit_flag == 1)
        {
            //strcpy(global_name_employee, "");
            char empty[50]={0};
            fileWriteGlobal(EMPLOYEE,empty);
            break;
        }
    }
}
void updataEmployee()
{
    char global_name_employee[50];
    FILE *fp = fopen(GLOBAL_VARIABLE_FILE_PATH, "r");
    GlobalVariable global = {0};
    fread(&global,sizeof(GlobalVariable),1,fp);
    fclose(fp);
    strcpy(global_name_employee,global.global_name_employee);
    DataList *head_E = createEmployeeList();
    DataList *end = head_E;
    char contact[20]={0}, password[20]={0};
    int choice = -1, quit_flag = 0;
    while (end != NULL)
    {
        if (strcmp(global_name_employee, end->datatype.employee.name) == 0)
        {
            while (1)
            {
                printf("***************************************\n");
                printf("请选择更新的信息：\n");
                printf("1.更新密码\n");
                printf("2.更新联系方式\n");
                printf("0.返回上一级\n");
                printf("输入选择：");
                setbuf(stdin, NULL);
                scanf("%d", &choice);
                switch (choice)
                {
                case 1:
                    while (1)
                    {
                        printf("输入密码：");
                        setbuf(stdin, NULL);
                        scanf("%s", password);
                        printf("确认输入密码：");
                        setbuf(stdin, NULL);
                        scanf("%s", contact);
                        if (strcmp(password, contact) == 0)
                        {
                            strcpy(end->datatype.employee.password, password);
                            printf("修改成功");
                            break;
                        }
                        else
                        {
                            printf("密码不一致请重新输入\n");
                            continue;
                        }
                    }
                    break;
                case 2:
                    printf("输入联系方式：");
                    setbuf(stdin, NULL);
                    scanf("%s", contact);
                    strcpy(end->datatype.employee.contact, contact);
                    printf("修改成功");
                    break;
                case 0:
                    quit_flag = 1;
                    break;
                default:
                    break;
                }
                if (quit_flag == 1)
                {
                    break;
                }
            }
            break;
        }
        end = end->pn;
    }
    fileWriteEmployee(head_E);
    freeList(head_E);
}